<template>
    <div class="user-woman">
        <el-form :inline="true" :model="formInline">
            <el-form-item label="地区">
                <el-input v-model="formInline.area" placeholder="地区"></el-input>
            </el-form-item>
            <el-form-item label="昵称">
                <el-input v-model="formInline.nickname" placeholder="昵称"></el-input>
            </el-form-item>
            <el-form-item label="手机号">
                <el-input v-model="formInline.phone" placeholder="手机号"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="search">搜索</el-button>
                <el-button type="primary" @click="reset">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table
            :header-cell-style="{color:'#555555'}"
            class="black"
            :data="tableData"
            max-height="650"
            stripe
            border
            style="width: 100%">
            <el-table-column
                prop="id"
                v-if="show = false">
            </el-table-column>
            <el-table-column
                prop="username"
                label="账号"
                align="center">
            </el-table-column>
            <el-table-column
                prop="area"
                label="地区"
                align="center">
            </el-table-column>
            <el-table-column
                prop="nickname"
                label="昵称"
                align="center">
            </el-table-column>
            <el-table-column
                prop="phone"
                label="手机号码"
                align="center">
            </el-table-column>
            <el-table-column
                prop="status"
                label="激活"
                align="center">
            </el-table-column>
            <el-table-column
                prop="identity"
                label="身份"
                align="center">
            </el-table-column>
            <el-table-column
                prop="applyCodeInfo"
                label="来源"
                align="center">
            </el-table-column>
            <el-table-column
                prop="loginTime"
                label="最近登录"
                align="center">
            </el-table-column>
            <el-table-column
                prop="registerTime"
                label="注册时间"
                align="center">
            </el-table-column>
            <el-table-column
                prop="statusTxt"
                label="账号状态"
                align="center">
            </el-table-column>
            <el-table-column
                prop="btnTxt"
                v-if="show = false">
            </el-table-column>
            <el-table-column
                prop="statusTmp"
                v-if="show = false">
            </el-table-column>
            <el-table-column label="操作" align="center" width="350">
                <template slot-scope="scope">
                    <el-button @click="onDetail(scope.row)" size="small">个人详情</el-button>
                    <el-button @click="onCheckIncome(scope.row)" size="small">收入记录</el-button>
                    <el-button @click="onFreezeOrThaw(scope.row)" size="small">{{scope.row.btnTxt}}</el-button>
                    <el-button @click="onDelClick(scope.row)" size="small">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="footer-page">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="page_size"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total_page">
            </el-pagination>
        </div>
        <el-dialog
            title="提示"
            :visible.sync="dialogVisible"
            width="30%">
            <span>确认删除吗？</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="onSureClick">确 定</el-button>
            </span>
        </el-dialog>
        <el-dialog
            title="收入记录"
            :visible.sync="incomeDlgVisible"
            width="50%">
            <div class="block">
                <span class="demonstration">日期选择：</span>
                <el-date-picker
                    v-model="dateValue"
                    type="daterange"
                    align="right"
                    unlink-panels
                    range-separator="——"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :picker-options="pickerOptions2"
                    value-format="yyyy-MM-dd">
                </el-date-picker>
                <el-button type="primary" @click="onReflash">刷新</el-button>
            </div>
            <timeline timeline-theme="lightblue" v-for="(value, key) in items" :key="key">
                <timeline-title bg-color="#f2d7e1">{{key}}</timeline-title>
                <timeline-item bg-color="#b0e6d1" v-for="v in value" :key="v">{{v}}</timeline-item>
            </timeline>
        </el-dialog>
    </div>
</template>

<script>
import { Timeline, TimelineItem, TimelineTitle } from 'vue-cute-timeline'

export default {
    name: 'user-woman',
    components: {
        Timeline,
        TimelineItem,
        TimelineTitle
    },
    data () {
        return {
            dialogVisible: false,
            del_station_id: '',
            list_params: {
                id: '',
                fuzzy_keyword: '',
                type: '',
                page: 1,
                page_size: 10
            },
            page: 1,
            page_size: 10,
            total_page: 0,
            formInline: {
                area: '',
                nickname: '',
                phone: ''
            },
            tableData: [],
            station_id: '',
            incomeDlgVisible: false,
            items: {},
            dateValue: '',
            pickerOptions2: {
                shortcuts: [{
                    text: '最近一周',
                    onClick (picker) {
                        const end = new Date()
                        const start = new Date()
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
                        picker.$emit('pick', [start, end])
                    }
                }, {
                    text: '最近一个月',
                    onClick (picker) {
                        const end = new Date()
                        const start = new Date()
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
                        picker.$emit('pick', [start, end])
                    }
                }, {
                    text: '最近三个月',
                    onClick (picker) {
                        const end = new Date()
                        const start = new Date()
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
                        picker.$emit('pick', [start, end])
                    }
                }]
            }
        }
    },
    created () {
        // this.tableData = []
    },
    mounted () {
        // 进来页面获取数据
        // this.getList(this.list_params)
        let params = {}
        params['page'] = 1
        params['limit'] = 10
        params['order'] = 'asc'
        params['sex'] = 1
        let data = {
            'params': params
        }
        this.getList(data)
    },
    methods: {
        search () {
            let params = {}
            params['page'] = 1
            params['limit'] = 10
            params['order'] = 'asc'
            params['sex'] = 1
            params['area'] = this.formInline.area
            params['nickname'] = this.formInline.nickname
            params['phone'] = this.formInline.phone
            let data = {
                'params': params
            }
            // 进来页面获取数据
            this.getList(data)
        },
        reset () {
            this.formInline = {
                area: '',
                nickname: '',
                phone: ''
            }
            let params = {}
            params['page'] = 1
            params['limit'] = 10
            params['order'] = 'asc'
            params['sex'] = 1
            let data = {
                'params': params
            }
            // 进来页面获取数据
            this.getList(data)
        },
        onEditClick (row) {
            this.$router.push({
                name: 'monitorSet.keyword.sourceEdit',
                params: {
                    womanId: row.station_id
                }
            })
        },
        onDelClick (row) {
            this.dialogVisible = true
            this.del_station_id = row.id
        },
        onSureClick () {
            this.dialogVisible = false
            this.$api.user.userDel({'id': this.del_station_id}, res => {
                if (res.code === 200) {
                    this.$message.success(res.msg)
                    this.reset()
                } else {
                    this.$message.error(res.msg)
                }
            })
        },
        onLimitClick () {
            console.log('禁用')
        },
        getList (data) {
            this.tableData = []
            this.$api.user.getUserList(data, res => {
                if (res.code === 200) {
                    this.getDetail(res.page.list)
                    this.total_page = res.page.totalCount
                    this.page_size = res.page.pageSize
                    this.page = res.page.currPage
                }
            })
        },
        getDetail (list) {
            for (let i = 0; i < list.length; i++) {
                this.tableData.push(list[i])
            }
        },
        onDetail (row) {
            this.$router.push({
                name: 'user.womandel',
                params: {
                    id: row.id
                }
            })
        },
        onCheckIncome (row) {
            this.state_id = row.id
            let params = {}
            params['id'] = row.id
            params['dateValue'] = this.dateValue
            this.$api.user.incomeList({'params': params}, res => {
                if (res.code === 200) {
                    this.items = res.data
                    console.log(this.items)
                    this.incomeDlgVisible = true
                } else {
                    this.$message.error(res.msg)
                }
            })
        },
        onReflash () {
            let params = {}
            params['id'] = this.state_id
            params['dateValue'] = this.dateValue[0] + ',' + this.dateValue[1]
            this.$api.user.incomeList({'params': params}, res => {
                if (res.code === 200) {
                    this.items = res.data
                    this.incomeDlgVisible = true
                } else {
                    this.$message.error(res.msg)
                }
            })
        },
        onFreezeOrThaw (row) {
            let params = {}
            params['id'] = row.id
            if (row.statusTmp === 'true') {
                params['status'] = false
            } else {
                params['status'] = true
            }
            this.$api.user.userFreezeOrThaw({'params': params}, res => {
                if (res.code === 200) {
                    this.$message.success(res.msg)
                    this.reset()
                } else {
                    this.$message.error(res.msg)
                }
            })
        },
        handleSizeChange (val) {
            this.page_size = val
            let params = {}
            params['page'] = this.page
            params['limit'] = val
            params['order'] = 'asc'
            params['sex'] = 1
            params['area'] = this.formInline.area
            params['nickname'] = this.formInline.nickname
            params['phone'] = this.formInline.phone
            let data = {
                'params': params
            }
            // 进来页面获取数据
            this.getList(data)
        },
        handleCurrentChange (val) {
            this.page = val
            let params = {}
            params['page'] = val
            params['limit'] = this.page_size
            params['order'] = 'asc'
            params['sex'] = 1
            params['area'] = this.formInline.area
            params['nickname'] = this.formInline.nickname
            params['phone'] = this.formInline.phone
            let data = {
                'params': params
            }
            // 进来页面获取数据
            this.getList(data)
        }
    }
}
</script>

<style lang="less" scoped>
    .user-woman {
        position: relative;
        width: 100%;
        height: 100%;
        .margin-bottom-12 {
            margin-bottom: 10px;
        }
        .el-row {
            margin-bottom: 20px;
            &:last-child {
                margin-bottom: 0;
            }
        }
        .el-col {
            border-radius: 4px;
        }
        .grid-content {
            position: relative;
            height: 40px;
        }
        .grid-padding {
            /* padding-left: 20px; */
            padding-right: 20px;
        }
        .grid-title {
            float: left;
            width: 72px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            color: #333;
            text-align: center;
        }
        .grid-input {
            float: left;
            width: 130px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            color: #333;
            text-align: center;
        }
        .row-bg {
            padding: 10px 0;
            background-color: #f9fafc;
        }
        .footer-page {
            width: 540px;
            margin: 0 auto;
            padding-top: 20px;
        }
    }
</style>
